package com.bbtShop.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bbtShop.aop.Login;
import com.bbtShop.core.model.*;
import com.bbtShop.service.OfficeTableService;
import freemarker.template.TemplateException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * @Author manke
 * @Date 2020/10/14 13:50
 * @Version 0.0.1
 */
@Api(value = "OfficeTableController", description = "排班表控制器")
@RestController
@RequestMapping("/OfficeTable")
public class OfficeTableController {
    @Autowired
    private OfficeTableService officeTableService;

    @ApiOperation(value = "getListOfficeTable", notes = "获取排班列表")
    @PostMapping("/getListOfficeTable")
    @Login(permission = "OfficeTable:getListOfficeTable")
    public ApiResponse<Object> getListOfficeTable(@RequestParam(required = false) Integer pageNum,
                                                  @RequestParam(required = false) Integer pageSize,
                                                  @RequestBody OfficeTable officeTable){
        IPage<OfficeTable> officeTableIPage = officeTableService.getListOfficeTable(pageNum,pageSize,officeTable);
        return ApiResponse.success(officeTableIPage);
    }

    @ApiOperation(value = "addPersonalOfficeTable", notes = "添加排班数据")
    @PostMapping("/addPersonalOfficeTable")
    @Login(permission = "OfficeTable:addPersonalOfficeTable")
    public ApiResponse<Object> addPersonalOfficeTable(@RequestBody OfficeTableVo officeTableVo){
        officeTableService.addPersonalOfficeTable(officeTableVo);
        return ApiResponse.success();
    }

    @ApiOperation(value = "downloadOfficeTable", notes = "生成用户排班文件")
    @PostMapping("/downloadOfficeTable")
    @Login(permission = "OfficeTable:downloadOfficeTable")
    public ApiResponse<String> downloadOfficeTable(@RequestBody FileTableVo fileTableVo) throws IOException, TemplateException {
        return ApiResponse.success(officeTableService.downloadOfficeTable(fileTableVo));
    }

    @ApiOperation(value = "delOfficeTable", notes = "删除排班表")
    @PostMapping("/delOfficeTable")
    @Login(permission = "OfficeTable:delOfficeTable")
    public ApiResponse<Object> delOfficeTable(@RequestBody Ids ids) {
        officeTableService.delOfficeTable(ids);
        return ApiResponse.success();
    }

    @ApiOperation(value = "updateOfficeTable", notes = "根据排班id修改排班信息")
    @PostMapping("/updateOfficeTable")
    @Login(permission = "OfficeTable:updateOfficeTable")
    public ApiResponse<Object> updateOfficeTable(@RequestBody UpdOfficeTableVo updOfficeTableVo) {
        officeTableService.updateOfficeTable(updOfficeTableVo);
        return ApiResponse.success();
    }

    @ApiOperation(value = "getOfficeTableInfo", notes = "根据id获取排班详情信息")
    @GetMapping("/getOfficeTableInfo")
    @Login(permission = "OfficeTable:getOfficeTableInfo")
    public ApiResponse< List<OfficeTableInfoDto> > getOfficeTableInfo(@RequestParam Integer id) {
        List<OfficeTableInfoDto> officeTableInfoDtos =officeTableService.getOfficeTableInfo(id);
        return ApiResponse.success(officeTableInfoDtos);
    }

    @ApiOperation(value = "getJobState", notes = "根据排班id,获取日期工作状态")
    @PostMapping("/getJobState")
    @Login(permission = "OfficeTable:getJobState")
    public ApiResponse<String> getJobState(@RequestBody JobStateVo jobStateVo) {
        String state =officeTableService.getJobState(jobStateVo);
        return ApiResponse.success(state);
    }

}
